class Api::V1::BaseController < ActionController::Base
  before_filter :signed_in_user
  before_filter :set_access_control_headers
  skip_before_filter :signed_in_user, :only => [:options]

  	def set_access_control_headers
    	headers["Access-Control-Allow-Origin"] = "*"
  		headers["Access-Control-Allow-Methods"] = "GET, PUT, POST, DELETE"
 		headers["Access-Control-Allow-Headers"] = "Origin, X-Requested-With, Content-Type, Accept"
  	end

	respond_to :json
	include SessionsHelper

	def options 
		return render :status => 200,
					:json => { :status_code => 200,
								:message => "Go ahead, no one is looking!"}
	end

	def expired_session

		if current_user
			if Time.now - current_user[:last_seen_at] > 600
				sign_out
				render :status => 401,
						:json => {
									:status_code => 401,
									:message => "The session has expired. You need to sign in again!",
									:content => ""
								 }
			else
				current_user[:last_seen_at] = Time.now
			end
		end
	end
end